package main

import "fmt"

func main() {
	nums := []int{1, 1, 2}
	duplicates := removeDuplicates(nums)
	fmt.Printf("%v\n", nums)
	fmt.Println(duplicates)
}

// 双指针
func removeDuplicates(nums []int) int {
	length := 0
	for i := 0; i < len(nums); i++ {
		if i == 0 {
			length++
			continue
		}
		if nums[i-1] != nums[i] {
			nums[length] = nums[i]
			length++
		}
	}
	return length
}
